﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DDD.Core;

using FloatComparer = DDDTest.Helper.FloatComparer;

namespace DDDTest.Core {
    using Object = DDD.Core.Object;

    [TestClass]
    public class TestObject {
        [TestMethod]
        public void Test_New1 () {
            var obj = (Object)new Node ();

            Assert.AreEqual (0, obj.UserID);
            Assert.AreEqual (0, obj.UserObject.Count);
            Assert.AreEqual (true, obj.IsDirty);
         }

        [TestMethod]
        public void Test_Dirty () {
            var obj = (Object)new Node ();
            obj.SetDirtyFlag (false);

            Assert.AreEqual (false, obj.IsDirty);
        }

        [TestMethod]
        public void Test_UniqID () {
            var obj1 = (Object)new Node ();
            var obj2 = (Object)new Node ();

            Assert.AreNotEqual (obj2.UniqueID, obj1.UniqueID);
        }

        [TestMethod]
        public void Test_UserID () {
            var obj = (Object)new Node ();
            obj.UserID = 100;

            Assert.AreEqual (100, obj.UserID);
        }

        [TestMethod]
        public void Test_GetUserObject () {
            var obj = (Object)new Node ();
            obj.SetUserObject ("Hello", "World");
            obj.SetUserObject ("Hello", "Good-bye");

            Assert.ReferenceEquals ("Good-bye", obj.GetUserObject ("Hello"));
        }

   


        [TestMethod]
        public void Test_GetName () {
            var obj = (Object)new Node ();

            Assert.AreEqual ("UserID", Object.GetName (() => obj.UserID));
        }

        [TestMethod]
        public void Test_References () {
            var nod = new Node ();
           var objs = nod.References;

            Assert.AreEqual (0, objs.Count ());
            Assert.AreEqual (true, objs.All (x => x != null));
        }

        [TestMethod]
        public void Test_Find () {

            var nod = new Node ();

            nod.UserID = 104;

            Assert.AreEqual (nod, nod.Find (104));
        }


        [TestMethod]
        public void Test_Finds () {
            var nod = new Node ();
            nod.UserID = 101;

            var n = nod.Finds (101);
            Assert.AreEqual (1, n.Count());
            Assert.AreEqual (nod, n[0]);
            
            n = nod.Finds (102);
            Assert.AreEqual (0, n.Count());
        }



    }
}
